<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>class - get -set</title>
</head>
<body>
    <script>
        class People{
            // getter 属性 当读取name属性时自动触发执行
            get name(){
                console.log('get name');
                return '123123';
            }
            // setter 属性  当设置name属性时自动触发执行，并且把设置的值作为参数传给 val
            set name(val){
                console.log('set name');
                console.log(val);
            }
        }

        let p1 = new People();
        console.log(p1.name);

        p1.name = '666';

    </script>
</body>
</html>